﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace cau2
{
    class SinhVienDAL
    {
        public SinhVienDAL()
        {
        }
        public DataTable DocDanhSachSinhVien()
        {
            SqlConnection conn = SqlDatabase.getConnection();
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from sinhvien ", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            return dt;


        }
        public void ThemSinhVien(string masv, string hosv, string tensv, string ngaysinh, string gioitinh, string makhoa)
        {
            SqlConnection conn = SqlDatabase.getConnection();
            conn.Open();
            SqlCommand cmd = new SqlCommand("insert into SinhVien values(N'" + masv + "'," + "N'" + hosv + "',N'" + tensv + "','" + ngaysinh + "',N'" + gioitinh + "',N'" + makhoa + "')", conn);
            cmd.ExecuteNonQuery();
        }
        public void XoaSinhVien(string masv)
        {
            SqlConnection conn = SqlDatabase.getConnection();
            conn.Open();
            SqlCommand cmd = new SqlCommand("delete from sinhvien where masv='" + masv + "'", conn);
            cmd.ExecuteNonQuery();

        }
        public void SuaSinhVien(string masv, string hosv, string tensv, string ngaysinh, string gioitinh, string makhoa)
        {
            SqlConnection conn = SqlDatabase.getConnection();
            conn.Open();
            SqlCommand cmd = new SqlCommand("update sinhvien set  hosv=N'" + hosv + "', tensv=N'" + tensv + "',ngaysinh='" + ngaysinh + "',gioitinh=N'" + gioitinh + "',makhoa=N'" + makhoa + "' where masv='" + masv + "'", conn);
            cmd.ExecuteNonQuery();
        }

    }

}
